	import java.awt.Font;
	import java.awt.Rectangle;
	import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;
	import javax.swing.JButton;
import javax.swing.JComboBox;
	import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
 * 
 *Gui of add Add Field window for the user's use
 */

	public class AddFieldGui implements ActionListener 
	{
		private JLabel AddSubject = null;
		private JLabel SubjectName = null;		
		public JTextField SubjectText = null;	
		public JComboBox FieldCombo2 = null;
		private JButton addSub = null;	
		private JLabel RemoveSubject = null;
		private JLabel SubjectName2 = null;
		private JButton remove = null;	 
		private JButton cancel = null;
		private JButton logout1 = null;
		public JPanel panel=new JPanel(); 
		
		/**
		 * This is the default constructor
		 */
		public AddFieldGui() {
			super();
			initialize();		
		}

		/**
		 * This method initializes this
		 * 
		 * @return void
		 */
	public void initialize() {		
			panel.setLayout(null);
			panel.add(getAddTitle(), null);
			panel.add(getAddTitle2(), null);
			panel.add(getsub1Title(), null);
			panel.add(getSubjectText(), null);
			getFieldCombo();		// first Field Combo		
			panel.add(getsub2Title(), null);			
			panel.add(getLogout1(), null);
			panel.add(getadd(), null);
			panel.add(getremove(), null);
			panel.add(getCancel(), null);
			panel.setVisible(false);
			panel.setEnabled(false);
			
		}

	/**
	 * This method initializes AddTitle : "Add Field"
	 * 	
	 * @return javax.swing.JLabel	
	 */
		private JLabel getAddTitle() 
		{
			if (AddSubject == null) {
				AddSubject = new JLabel("Add Field");
				AddSubject.setFont(new Font("David",Font.ITALIC,34));
				AddSubject.setBounds(new Rectangle(120, 40, 283, 44));
			}
			return AddSubject;
		}
			/**
	 * This method initializes sub1Title : "Enter Field :"
	 * 	
	 * @return javax.swing.JLabel	
	 */
		private JLabel getsub1Title() 
		{
			if (SubjectName == null) {
				SubjectName = new JLabel("Enter Field :");
				SubjectName.setFont(new Font("David",Font.ITALIC,16));
				SubjectName.setBounds(new Rectangle(20, 120, 150, 44));
			}
			return SubjectName;
		}		
		
	/** This method initializes SubjectText TextField and set key listener for it
	 * 	
	 * @return javax.swing.JTextField	
	 */
		JTextField getSubjectText() {
			if (SubjectText == null) {
				SubjectText = new JTextField();
				SubjectText.setBounds(new Rectangle(130, 120, 100, 36));
				SubjectText.addKeyListener(new java.awt.event.KeyAdapter() {
					public void keyTyped(java.awt.event.KeyEvent e) 
		             {
		                 Character c=e.getKeyChar();
		                 if( c.charValue()==':' || c.charValue()=='*' || c.charValue()=='-' )
		                 {
		                     e.consume();
		                     //Toolkit.getDefaultToolkit().beep();
		                     JOptionPane.showMessageDialog(null,"Invalid key !!!!","ERROR",JOptionPane.ERROR_MESSAGE);
		                     return;
		                 }
		             }	
				});
			}
			return SubjectText;
		}
	/** This method initializes FieldCombo ComboBox and sets it with fields retreived form DB
	 * 	
	 * @return javax.swing.JComboBox	
	 */					
		private void getFieldCombo() 
		{
			Main.bookManagementCTRL.AddFieldCTRL.o_GetFields(this);	
		}		
	/** This method initializes Add Button and set action listener for it
	 * 	
	 * @return javax.swing.JButton	
	 */
		private JButton getadd() 
		{
			if (addSub == null) {
				addSub = new JButton("Add Field");
				addSub.setBounds(new Rectangle(250, 110, 120, 60));
				addSub.addActionListener(this);			
			}
			return addSub;
		}		
	/** This method initializes sub1Title : "Remove Field"
	 * 	
	 * @return javax.swing.JLabel	
	 */
		private JLabel getAddTitle2() 
		{
			if (RemoveSubject == null) {
				RemoveSubject = new JLabel("Remove Field");
				RemoveSubject.setFont(new Font("David",Font.ITALIC,36));
				RemoveSubject.setBounds(new Rectangle(120, 210, 283, 44));
			}
			return RemoveSubject;
		}
	/** This method initializes sub1Title : "Select Field :"
	 * 	
	 * @return javax.swing.JLabel	
	 */	
		private JLabel getsub2Title() 
		{
			if (SubjectName2 == null) {
				SubjectName2 = new JLabel("Select Field :");
				SubjectName2.setFont(new Font("David",Font.ITALIC,16));
				SubjectName2.setBounds(new Rectangle(20, 290, 150, 44));				
			}
			return SubjectName2;
		}		
	/** This method initializes Remove Button and set action listener for it
	 * 	
	 * @return javax.swing.JButton	
	 */		
		private JButton getremove() 
		{
			if (remove == null) {
				remove = new JButton("Remove Field");
				remove.setBounds(new Rectangle(250, 280, 120, 60));
				remove.addActionListener(this);					
			}
			return remove;
		}				
		/** This method initializes Back Button and set action listener for it
	 * 	
	 * @return javax.swing.JButton	
	 */	
		private JButton getCancel() {
			if (cancel == null) {
				cancel = new JButton("Back");
				cancel.setBounds(new Rectangle(318, 8, 74, 24));
				cancel.addActionListener(this);
			}
			return cancel;
		}
		/**
		 * This method initializes logout1 and set action listener for it
		 * 	
		 * @return javax.swing.JButton	
		 */
		JButton getLogout1() {
			if (logout1 == null) {
				logout1 = new JButton("Logout");
				logout1.setBounds(new Rectangle(402, 8, 74, 24));
				logout1.addActionListener(this);
			}
			return logout1;
		}


		public void actionPerformed(ActionEvent ae)
		{		
			if(ae.getSource()==addSub)
				Main.bookManagementCTRL.AddFieldCTRL.o_AddField(this);
			
			if(ae.getSource()==remove)
			{
				if(JOptionPane.showConfirmDialog(null, "Are you sure you want to remove that Field? ","Confirmation" ,JOptionPane.OK_CANCEL_OPTION) == 0)
						Main.bookManagementCTRL.AddFieldCTRL.o_RemoveField(this);				
			}
				
			
			if(ae.getSource()==cancel)			
				Main.bookManagementCTRL.AddFieldCTRL.o_Back(this.panel);
			
			if(ae.getSource()==getLogout1())				
				Main.bookManagementCTRL.o_logout(this.panel);
			
					
		}

	}
